package nl.boektrust.btsoep.server;

import org.restlet.Application;
import org.restlet.Restlet;
import org.restlet.routing.Extractor;
import org.restlet.routing.Router;
import org.restlet.routing.TemplateRoute;

public class RestApplication extends Application {
	   /** 
     * Creates a root Restlet that will receive all incoming calls. 
     */  
    @Override  
    public synchronized Restlet createInboundRoot() {  
    	// Create a router Restlet that routes each call to a  
    	// new instance of HelloWorldResource.  
    	Router router = new Router(getContext());  

    	// Defines only one route 
    	TemplateRoute route = router.attach("/book/{recordReference}", RestBookResource.class); 
    	route = router.attach("/bookByKey/{key}", RestBookByKeyResource.class); 
       
        Extractor e = new Extractor();

        //router.attach(e);
        route.setMatchingQuery(false);
        e.extractFromQuery("key0","key0", true);
        e.extractFromQuery("key1","key1", true);
        e.extractFromQuery("key2","key2", true);
        e.extractFromQuery("key3","key3", true);
        e.extractFromQuery("key4","key4", true);
        e.extractFromQuery("key5","key5", true);
        e.extractFromQuery("value0","value0", true);
        e.extractFromQuery("value1","value1", true);
        e.extractFromQuery("value2","value2", true);
        e.extractFromQuery("value3","value3", true);
        e.extractFromQuery("value4","value4", true);
        e.extractFromQuery("value5","value5", true);
        e.extractFromQuery("flags0","flags0", true);
        e.extractFromQuery("flags1","flags1", true);
        e.extractFromQuery("flags2","flags2", true);
        e.extractFromQuery("flags3","flags3", true);
        e.extractFromQuery("flags4","flags4", true);
        e.extractFromQuery("limit","limit", true);
        e.extractFromQuery("offset","offset", true);
        e.extractFromQuery("resultSetType","resultSetType", true);

        e.setNext(RestBooksResource.class);
        route = router.attach("/books", e);
        route.setMatchingQuery(false);

        route = router.attach("/search", e);
        route.setMatchingQuery(false);

//        route = router.attach("/books", RestBooksResource.class);  

        //router.attach("/person", BookResource.class);  
        //router.attach("/persons", BookResource.class);  
        //router.attach("/books", BookResource.class);  
  
        return router;  
    }  

}
